// pages/index/psychology/qa/qa.js

import dayjs from 'dayjs'
const app = getApp();
Page({

  /**
   * Page initial data
   */
  data: {
    problems:[],
  },
 
  methods:{
    formatRelativeDate(date){
      const now = dayjs();
      const targetDate = dayjs(date);
      const diffDays = now.diff(targetDate, 'day');
      if (diffDays === 0) {
        return '今天';
      } else if (diffDays === 1) {
        return '昨天';
      } else if (diffDays === 2) {
        return '前天';
      } else if (diffDays > 2 && diffDays <= 7) {
        return targetDate.fromNow();  
      } else {
        return targetDate.format('YYYY-MM-DD');  // 超过一周直接显示日期
      }
    }


  },

  checkDetail(e){
    console.log(e);
    wx.navigateTo({
      url: '/pages/index/psychology/qa/qacomment/qacomment?id='+e.detail.id,
    })
  },
  onLoad(options){
    console.log("hello");
    wx.request({
      url: 'http://localhost:8080/consult/all?pageNum=1&pageSize=30',
      success:(res) => {
          this.setData({
            problems:res.data.data.list
          })
      }
    })
  }
})